package com.example.neusoft.yuejian_12.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.neusoft.yuejian_12.JavaBean.Club;
import com.example.neusoft.yuejian_12.R;

import java.util.List;

/**
 * Created by admin on 2017/10/24.
 */

public class ClassDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;

    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public ClassDetailAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.class_item, parent, false);
        return new ClassDetailAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final Club.ClubcourseEntity entity = (Club.ClubcourseEntity) mDataList.get(position);

        if (null == entity)
            return;
        ClassDetailAdapter.ViewHolder viewHolder = (ClassDetailAdapter.ViewHolder) holder;
        viewHolder.name.setText("课程名："+entity.getCourse_name());
        viewHolder.intro.setText("简    介："+entity.getIntroduction());
        viewHolder.price.setText(entity.getCourse_price()+"元");
        viewHolder.rating.setRating(Float.parseFloat(entity.getDegree()));
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        RatingBar rating;
        TextView name,intro,price;

        public ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.name);
            intro = (TextView) itemView.findViewById(R.id.intro);
            price = (TextView) itemView.findViewById(R.id.price);
            rating = (RatingBar) itemView.findViewById(R.id.rating);
        }
    }
}

